package com.yidu.best.basicSetup.securityset.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.best.basicSetup.securityset.dao.SecurityDao;
import com.yidu.best.basicSetup.securityset.domain.Security;
import com.yidu.best.basicSetup.securityset.domain.SecurityVo;
import com.yidu.best.basicSetup.securityset.service.SecurityService;
import com.yidu.best.basicSetup.securityset.util.IDUtil;

@Service
public class SecurityServiceImpl implements SecurityService {
	@Autowired
	private SecurityDao securityDao;
	
	@Override
	public Map<String,Object> findSecurity(SecurityVo securityVo) {
		// 调用dao层方法，查询数量。
		int count = securityDao.findCountSecurity(securityVo);
		//计算页码
		int page = (securityVo.getPage()-1)*securityVo.getLimit();
		securityVo.setPage(page);
		//调用dao层方法分页查询
		List<Security> securityList = securityDao.findSecurity(securityVo);
		Map<String  ,Object> map = new HashMap<String, Object>();
		//将数据存入map中
		map.put("code", 0);
		map.put("count", count);
		map.put("data", securityList);
		System.out.println(map);
		return map;
	}

	@Override
	public int addSecurity(Security security) {
		security.setSecurityId(IDUtil.getUUID());
		security.setIssueDate(new Date());
		int rs =securityDao.addSecurity(security);
	
		return rs;
	}

	@Override
	public int updateSecurity(Security security) {
		return securityDao.updateSecurity(security);
	}

	@Override
	public int deleteSecurity(String securityId) {

		return securityDao.deleteSecurity(securityId);
	}
	
}
